package org.caw.ws;

import java.util.List;

import javax.jws.WebParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.caw.domain.Row;
import org.caw.domain.descriptor.TableDescriptor;
import org.caw.ws.domain.TableUpdateAction;
import org.springframework.stereotype.Service;

@Produces({ "application/json" })
@Consumes({ "application/json" })
@Service("tableService")
@Path("/tables")
public interface TableService {

	@GET
	Response get(@QueryParam("details") boolean details);

	@GET
	@Path("/{tableName}")
	Response get(@PathParam("tableName") String tableName);

	@PUT
	@Path("/{tableName}")
	Response create(@PathParam("tableName") String tableName, @WebParam(name = "descriptor") TableDescriptor descriptor, @QueryParam("overwrite") boolean overwrite);

	@DELETE
	@Path("/{tableName}")
	Response delete(@PathParam("tableName") String tableName);

	@POST
	@Path("/{tableName}/actions/{action}")
	Response update(@PathParam("tableName") String tableName, @PathParam("action") TableUpdateAction action);

	@POST
	@Path("/{tableName}")
	Response update(@PathParam("tableName") String tableName, @WebParam(name = "descriptor") TableDescriptor descriptor);

	@Deprecated
	@GET
	@Path("/{tableName}/_rows")
	Response multiget(@PathParam("tableName") String tableName, @QueryParam("rowkey") List<String> rowkeys, @QueryParam("column") List<String> columns, @QueryParam("maxversions") Integer maxversions,
			@QueryParam("timestamp") Long timestamp);

	@Deprecated
	@GET
	@Path("/{tableName}/_rows/scan")
	Response scan(@PathParam("tableName") String tableName, @QueryParam("filter") String filter, @QueryParam("startKey") String startKey, @QueryParam("endKey") String endKey,
			@QueryParam("limit") Integer limit, @QueryParam("column") List<String> columns, @QueryParam("maxversions") Integer maxversions, @QueryParam("timestamp") Long timestamp);

	@GET
	@Path("/{tableName}/rows")
	Response getRows(@PathParam("tableName") String tableName, @QueryParam("filter") String filter, @QueryParam("startKey") String startKey, @QueryParam("endKey") String endKey,
			@QueryParam("limit") Integer limit, @QueryParam("rowkey") List<String> rowkeys, @QueryParam("column") List<String> columns, @QueryParam("maxversions") Integer maxversions,
			@QueryParam("timestamp") Long timestamp);

	@GET
	@Path("/{tableName}/rows/{rowkey}")
	Response get(@PathParam("tableName") String tableName, @PathParam("rowkey") String rowkey, @QueryParam("column") List<String> columns, @QueryParam("maxversions") Integer maxversions,
			@QueryParam("timestamp") Long timestamp);

	@DELETE
	@Path("/{tableName}/rows/{rowkey}")
	Response delete(@PathParam("tableName") String tableName, @PathParam("rowkey") String rowkey, @QueryParam("timestamp") Long timestamp, @QueryParam("column") List<String> columns);

	@PUT
	@Path("/{tableName}/rows/{rowkey}")
	Response create(@PathParam("tableName") String tableName, @PathParam("rowkey") String rowkey, @WebParam(name = "row") Row row, @QueryParam("overwrite") boolean overwrite);

	@POST
	@Path("/{tableName}/rows/{rowkey}")
	Response update(@PathParam("tableName") String tableName, @PathParam("rowkey") String rowkey, @WebParam(name = "row") Row row);

}
